<?php

namespace JLPay\Models\Openmerch\Query;

use JLPay\Models\BaseResponse;

/**
 * 商户基本信息查询响应
 */
class MerchBaseInfoQueryResponse extends BaseResponse
{
    // 基础信息
    protected string $merchNo = '';  // 商户号
    protected string $merchName = '';  // 商户名称
    protected string $registerTime = '';  // 进件时间
    protected string $merchStatus = '';  // 商户状态
    protected string $productType = '';  // 产品类型
    protected string $signMode = '';  // 协议类型
    protected string $agentId = '';  // 服务商编号

    // 进件结果
    protected string $signId = '';  // 协议编号
    protected string $signUrl = '';  // 协议链接

    // 经营信息
    protected string $merchShortname = '';  // 商户经营名称
    protected string $merchEnglishName = '';  // 商户英文名称
    protected string $addressCode = '';  // 经营地址-省市区
    protected string $addressDetail = '';  // 经营地址-详细地址
    protected string $mccCode = '';  // 所属行业

    // 结算设置
    protected string $settleMode = '';  // 结算方式
    protected string $dayCut = '';  // 营业周期
    protected string $accountChangeFlag = '';  // 是否允许商户自主变更结算账户
    protected string $postscript = '';  // 结算附言
    protected array $rateInfo = [];  // 费率列表

    // 辅助证明材料
    protected string $bankServerId = '';  // 银行客户经理工号
    protected string $bankCode = '';  // 银行编号

    // 身份信息
    protected string $merchType = '';  // 主体类型

    // 营业证明信息
    protected string $licenseType = '';  // 执照类型
    protected string $licenseNo = '';  // 注册号/统一社会信用代码
    protected string $certNumber = '';  // 登记证书编号
    protected string $licenseName = '';  // 商户法定名称
    protected string $businessScope = '';  // 经营范围
    protected string $licenseAddress = '';  // 注册地址
    protected string $periodBegin = '';  // 有效期限开始日期
    protected string $periodEnd = '';  // 有效期限结束日期

    // 经营者/法人信息
    protected string $idDocType = '';  // 证件类型
    protected string $idCardName = '';  // 经营者/法人姓名 (需要解密)
    protected string $idCardEnglishName = '';  // 经营者/法人英文名称 (需要解密)
    protected string $idCardNo = '';  // 经营者/法人证件号码 (需要解密)
    protected string $legalPersonName = '';  // 法人姓名 (需要解密)
    protected string $legalPersonPhone = '';  // 经营者/法人手机号码 (需要解密)
    protected string $cardPeriodBegin = '';  // 证件有效期开始时间
    protected string $cardPeriodEnd = '';  // 证件有效期结束时间

    /**
     * 构造函数
     *
     * @param array|null $responseArray
     */
    public function __construct(?array $responseArray = null)
    {
        parent::__construct($responseArray);
        
        if ($responseArray) {
            // 基础信息
            $this->merchNo = $responseArray['merch_no'] ?? '';
            $this->merchName = $responseArray['merch_name'] ?? '';
            $this->registerTime = $responseArray['register_time'] ?? '';
            $this->merchStatus = $responseArray['merch_status'] ?? '';
            $this->productType = $responseArray['product_type'] ?? '';
            $this->signMode = $responseArray['sign_mode'] ?? '';
            $this->agentId = $responseArray['agent_id'] ?? '';

            // 进件结果
            $this->signId = $responseArray['sign_id'] ?? '';
            $this->signUrl = $responseArray['sign_url'] ?? '';

            // 经营信息
            $this->merchShortname = $responseArray['merch_shortname'] ?? '';
            $this->merchEnglishName = $responseArray['merch_english_name'] ?? '';
            $this->addressCode = $responseArray['address_code'] ?? '';
            $this->addressDetail = $responseArray['address_detail'] ?? '';
            $this->mccCode = $responseArray['mcc_code'] ?? '';

            // 结算设置
            $this->settleMode = $responseArray['settle_mode'] ?? '';
            $this->dayCut = $responseArray['day_cut'] ?? '';
            $this->accountChangeFlag = $responseArray['account_change_flag'] ?? '';
            $this->postscript = $responseArray['postscript'] ?? '';

            // 费率列表
            $rateInfoList = $responseArray['rate_info'] ?? [];
            if ($rateInfoList) {
                foreach ($rateInfoList as $rateData) {
                    if (is_array($rateData)) {
                        $rateInfo = new RateInfoDto();
                        $rateInfo->setFeeType($rateData['fee_type'] ?? '');
                        $rateInfo->setFeeRate($rateData['fee_rate'] ?? '');
                        $this->rateInfo[] = $rateInfo;
                    }
                }
            }

            // 辅助证明材料
            $this->bankServerId = $responseArray['bank_server_id'] ?? '';
            $this->bankCode = $responseArray['bank_code'] ?? '';

            // 身份信息
            $this->merchType = $responseArray['merch_type'] ?? '';

            // 营业证明信息
            $this->licenseType = $responseArray['license_type'] ?? '';
            $this->licenseNo = $responseArray['license_no'] ?? '';
            $this->certNumber = $responseArray['cert_number'] ?? '';
            $this->licenseName = $responseArray['license_name'] ?? '';
            $this->businessScope = $responseArray['business_scope'] ?? '';
            $this->licenseAddress = $responseArray['license_address'] ?? '';
            $this->periodBegin = $responseArray['period_begin'] ?? '';
            $this->periodEnd = $responseArray['period_end'] ?? '';

            // 经营者/法人信息
            $this->idDocType = $responseArray['id_doc_type'] ?? '';
            $this->idCardName = $responseArray['id_card_name'] ?? '';
            $this->idCardEnglishName = $responseArray['id_card_english_name'] ?? '';
            $this->idCardNo = $responseArray['id_card_no'] ?? '';
            $this->legalPersonName = $responseArray['legal_person_name'] ?? '';
            $this->legalPersonPhone = $responseArray['legal_person_phone'] ?? '';
            $this->cardPeriodBegin = $responseArray['card_period_begin'] ?? '';
            $this->cardPeriodEnd = $responseArray['card_period_end'] ?? '';
        }
    }

    /**
     * 获取需要解密的敏感字段列表
     *
     * @return array
     */
    public function getSensitiveFields(): array
    {
        return [
            'id_card_name',           // 经营者/法人姓名
            'id_card_english_name',   // 经营者/法人英文名称
            'id_card_no',             // 经营者/法人证件号码
            'legal_person_name',      // 法人姓名
            'legal_person_phone',     // 经营者/法人手机号码
        ];
    }

    // 基础信息 getter/setter
    public function getMerchNo(): string { return $this->merchNo; }
    public function getMerchName(): string { return $this->merchName; }
    public function getMerchStatus(): string { return $this->merchStatus; }
    public function getProductType(): string { return $this->productType; }
    public function getSignMode(): string { return $this->signMode; }
    public function getAgentId(): string { return $this->agentId; }

    // 进件结果 getter/setter
    public function getSignId(): string { return $this->signId; }
    public function getSignUrl(): string { return $this->signUrl; }

    // 经营信息 getter/setter
    public function getMerchShortname(): string { return $this->merchShortname; }
    public function getMerchEnglishName(): string { return $this->merchEnglishName; }
    public function getAddressCode(): string { return $this->addressCode; }
    public function getAddressDetail(): string { return $this->addressDetail; }
    public function getMccCode(): string { return $this->mccCode; }

    // 结算设置 getter/setter
    public function getSettleMode(): string { return $this->settleMode; }
    public function getDayCut(): string { return $this->dayCut; }
    public function getAccountChangeFlag(): string { return $this->accountChangeFlag; }
    public function getPostscript(): string { return $this->postscript; }
    public function getRateInfo(): array { return $this->rateInfo; }

    // 辅助证明材料 getter/setter
    public function getBankServerId(): string { return $this->bankServerId; }
    public function getBankCode(): string { return $this->bankCode; }

    // 身份信息 getter/setter
    public function getMerchType(): string { return $this->merchType; }

    // 营业证明信息 getter/setter
    public function getLicenseType(): string { return $this->licenseType; }
    public function getLicenseNo(): string { return $this->licenseNo; }
    public function getCertNumber(): string { return $this->certNumber; }
    public function getLicenseName(): string { return $this->licenseName; }
    public function getBusinessScope(): string { return $this->businessScope; }
    public function getLicenseAddress(): string { return $this->licenseAddress; }
    public function getPeriodBegin(): string { return $this->periodBegin; }
    public function getPeriodEnd(): string { return $this->periodEnd; }

    // 经营者/法人信息 getter/setter
    public function getIdDocType(): string { return $this->idDocType; }
    public function getIdCardName(): string { return $this->idCardName; }
    public function getIdCardEnglishName(): string { return $this->idCardEnglishName; }
    public function getIdCardNo(): string { return $this->idCardNo; }
    public function getLegalPersonName(): string { return $this->legalPersonName; }
    public function getLegalPersonPhone(): string { return $this->legalPersonPhone; }
    public function getCardPeriodBegin(): string { return $this->cardPeriodBegin; }
    public function getCardPeriodEnd(): string { return $this->cardPeriodEnd; }
} 